import { toast } from 'nc-lightapp-front';

export default function afterEvent(attrcode, newValue, record, index, oldValue) {
    //区分body还是head的修改
    const rowIndex = record.rowIndex;
    const pk_erminvoice = record.pk_erminvoice.value;
    const isBody = record.pk_erminvoice_b ? true : false;
    
    const { transferTable } = this.props;
    const { setRowDataByIndex } = transferTable;
    //head 不允许修改已验证通过的发票行数据
    const isValid = record['inspectstatus'].value
    if( isValid == 1) {
        record[attrcode].value = oldValue
        setRowDataByIndex.call(this, 'head', record, index)
        toast({ content: '发票已查验,不可修改', color: 'danger' })
        return
    }

    if(!this.changeKeys[pk_erminvoice]) {
        this.changeKeys[pk_erminvoice] = {head: [], body: {}}
    }

    if(isBody) {
        if(!this.changeKeys[pk_erminvoice].body[record.pk_erminvoice_b.value]) {
            this.changeKeys[pk_erminvoice].body[record.pk_erminvoice_b.value] = []
        }
        if(this.changeKeys[pk_erminvoice].body[record.pk_erminvoice_b.value].indexOf(attrcode) < 0) {
            this.changeKeys[pk_erminvoice].body[record.pk_erminvoice_b.value].push(attrcode)
        }
    } else {
        if(this.changeKeys[pk_erminvoice].head.indexOf(attrcode) < 0) {
            this.changeKeys[pk_erminvoice].head.push(attrcode)
        }
    }
}